function previewImage(list, image, base_path){
	form = document.adminForm;
	srcList = eval("form." + list);
	srcImage = eval("document." + image);
	var srcOption = srcList.options[(srcList.selectedIndex < 0) ? 0 : srcList.selectedIndex];
	var fileName = srcOption.text;
	var fileName2 = srcOption.value;
	if (fileName.length == 0 || fileName2.length == 0) {
		srcImage.src = 'images/blank.gif';
	} 
	else {
		srcImage.src = base_path + fileName2;
	}
}

function addSelectedToList( frmName, srcListName, tgtListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );
	var tgtList = eval( 'form.' + tgtListName );

	var srcLen = srcList.length;
	var tgtLen = tgtList.length;
	var tgt = "x";

	//build array of target items
	for (var i=tgtLen-1; i > -1; i--) {
		tgt += "," + tgtList.options[i].value + ","
	}

	//Pull selected resources and add them to list
	for (var i=0; i < srcLen; i++) {
		if (srcList.options[i].selected && tgt.indexOf( "," + srcList.options[i].value + "," ) == -1) {
			opt = new Option( srcList.options[i].text, srcList.options[i].value );
			tgtList.options[tgtList.length] = opt;
		}
	}
}

function delSelectedFromList( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	var srcLen = srcList.length;

	for (var i=srcLen-1; i > -1; i--) {
		if (srcList.options[i].selected) {
			srcList.options[i] = null;
		}
	}
}

function check_form_target(form_target, redirection_url_name , redirection_message){
	var redirect_url = document.getElementsByName(redirection_url_name);
	var redirect_msg = document.getElementsByName(redirection_message);
	
	if(form_target.value == '0'){
		if(redirect_url.length > 0){
			if(redirect_url[0].disabled != true){
				redirect_url[0].disabled = true ;
			}
			redirect_url[0].value = '' ;    
		}
		if(redirect_msg.length > 0){
			if(redirect_msg[0].disabled != true){
				redirect_msg[0].disabled = true;
			}
			redirect_msg[0].value = '' ;    
		}                
	} 
	else if(form_target.value == '1'){
		if(redirect_url.length > 0){
			if(redirect_url[0].disabled != false){
				redirect_url[0].disabled = false ;
			}
			redirect_url[0].value = 'http://';
		}
		if(redirect_msg.length > 0){
			if(redirect_msg[0].disabled != false){
				redirect_msg[0].disabled = false ;
			}
			redirect_msg[0].value = 'Thank You';
		}                
	}            
}

function selectQuestion(value){
	var index  = value.selectedIndex;
	var option = value.options[index].value;
	
	if(option=="1" || option=="3" || option=="4"){
		var div_answer = document.getElementById("div_answer").style.display = "block";
		var div_another_answer = document.getElementById("div_another_answer").style.display = "block";
		var div_columns_names = document.getElementById("div_columns_names").style.display = "none";
		var div_constant = document.getElementById("div_constant").style.display = "none";
		var table_menu_column = document.getElementById("table_menu_column").style.display = "none";
	}
	if(option=="2" || option=="5" || option=="10" || option=="13"){
		var div_answer = document.getElementById("div_answer").style.display = "block";
		var div_another_answer = document.getElementById("div_another_answer").style.display = "none";
		var div_columns_names = document.getElementById("div_columns_names").style.display = "none";
		var div_constant = document.getElementById("div_constant").style.display = "none";
		var table_menu_column = document.getElementById("table_menu_column").style.display = "none";
	}
	if(option=="6" || option=="7"){
		var div_answer = document.getElementById("div_answer").style.display = "block";
		var div_another_answer = document.getElementById("div_another_answer").style.display = "none";
		var div_columns_names = document.getElementById("div_columns_names").style.display = "block";
		var div_constant = document.getElementById("div_constant").style.display = "none";
		var table_menu_column = document.getElementById("table_menu_column").style.display = "none";
	}
	if(option=="12"){
		var div_answer = document.getElementById("div_answer").style.display = "block";
		var div_another_answer = document.getElementById("div_another_answer").style.display = "none";
		var div_columns_names = document.getElementById("div_columns_names").style.display = "none";
		var div_constant = document.getElementById("div_constant").style.display = "block";	
		var table_menu_column = document.getElementById("table_menu_column").style.display = "none";
	}
	if(option=="11" || option=="0"){
		var div_answer = document.getElementById("div_answer").style.display = "none";
		var div_another_answer = document.getElementById("div_another_answer").style.display = "none";
		var div_columns_names = document.getElementById("div_columns_names").style.display = "none";
		var div_constant = document.getElementById("div_constant").style.display = "none";
		var table_menu_column = document.getElementById("table_menu_column").style.display = "none";
	}
	if(option=="8"){
		var div_answer = document.getElementById("div_answer").style.display = "block";
		var div_another_answer = document.getElementById("div_another_answer").style.display = "none";
		var div_columns_names = document.getElementById("div_columns_names").style.display = "none";
		var div_constant = document.getElementById("div_constant").style.display = "none";
		var table_menu_column = document.getElementById("table_menu_column").style.display = "block";
	}
	return true;
}

function changeSurvey(value, page_id){
	var index  = value.selectedIndex;
	var survey = value.options[index].value;
	
	var req = new Request.HTML({
		method: 'get',
		url: 'components/com_surveys/javascript/ajax.php?task=change_survey&survey='+survey+'&page_id='+page_id,
		data: { 'do' : '1' },
		update: $('page_list'),
		onComplete: function(response){		
		}
	}).send();
}

function printMenus(value){
	var index  = value.selectedIndex;
	var number = value.options[index].value;
	
	if(number==0){
		for(i=1; i<=10; i++){
			document.getElementById("menu_chois_"+i).style.display = "none";
		}	
	}
	else{
		var temp = parseInt(number)+1;
		for(j=temp; j<=10; j++){
			document.getElementById("menu_chois_"+j).style.display = "none";
		}
		for(i=1; i<=number; i++){
			document.getElementById("menu_chois_"+i).style.display = "block";
		}				
	}
}

function changeSurveySkip(value){
	var index  = value.selectedIndex;
	var survey_id = value.options[index].value;
	
	var req = new Request.HTML({
		method: 'get',
		url: 'components/com_surveys/javascript/ajax.php?task=change_survey_skip&survey_id='+survey_id,
		data: { 'do' : '1' },
		update: $('page_skip'),
		onComplete: function(response){		
		}
	}).send();
}

function changePageSkip(value, survey_id){
	var index  = value.selectedIndex;
	var page_id = value.options[index].value;
	
	var req = new Request.HTML({
		method: 'get',
		url: 'components/com_surveys/javascript/ajax.php?task=change_page_skip&page_id='+page_id+"&div=question&survey_id="+survey_id,
		data: { 'do' : '1' },
		update: $('question_skip'),
		onComplete: function(response){		
		}
	}).send();
	
	var req = new Request.HTML({
		method: 'get',
		url: 'components/com_surveys/javascript/ajax.php?task=change_page_skip&page_id='+page_id+"&div=page_target_skip&survey_id="+survey_id,
		data: { 'do' : '1' },
		update: $('page_target_skip'),
		onComplete: function(response){		
		}
	}).send();
}

function changeQuestionSkip(value, survey_id){
	var index  = value.selectedIndex;
	var question_id = value.options[index].value;
	
	var req = new Request.HTML({
		method: 'get',
		url: 'components/com_surveys/javascript/ajax.php?task=change_question_skip&question_id='+question_id,
		data: { 'do' : '1' },
		update: $('answers_skip'),
		onComplete: function(response){		
		}
	}).send();		
}